<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="edu.whu.rose.clock.ssql.sang.dataStruct.SimpleAnswer" %>
<%@page import="com.tomcat.hbase.MyHbase" %>
<%@page import="java.util.HashMap" %>

<html lang='zh-CN' xml:lang='zh-CN' xmlns='http://www.w3.org/1999/xhtml'>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="Content-Language" content="zh-CN"/>
  
<link  href="more-style.css"  rel="stylesheet" type="text/css">

</head>

<body>

<DIV id= "myTitle">
Find Grape 0.1
</DIV>

<DIV id="banner_search">
	<FORM  action="/WebSearch/FindResult">
		<INPUT class = "text_input" value="" name="keyword"> 
		<INPUT class="search_button" type="submit" value="Search"> 
	</FORM>
</DIV>

<hr>
<% String time=(String)request.getAttribute("time");
		if(time !=null){%>
			<%="Time exhausted: "+time%>
<%		}%>

<DIV id=result_content>
<% 
	String[][] result =(String[][]) request.getAttribute("moreResult"); 
	int[][] orderByYear = (int[][])request.getAttribute("orderYear"); 
	String id=(String)request.getAttribute("id");
	MyHbase myHbase = MyHbase.getInstance(); %>
	<%="<h4>Source info:</h4>"%>
<%	String[] columns = myHbase.getInfoTest(Integer.parseInt(id)).split("@@");%>

	<table border="1" id="tb">
<%	for(String column : columns){ %>
		<th>
		<%=column.split(":")[0] %>
		</th>
<%	}%>	
		<th><%="&nbsp;"%></th>
		<tr>
	<%	for(String column : columns){ %>
			<td>
			<%=column.split(":")[1] %>
			</td>
	<%	}%>
		<td>
			<%="<a href=\"/WebSearch/MoreInfo?id="+id+"\">Enter</a>" %>
		</td>
		</tr>
	</table>
	<br><hr><br>
	
	<%	if(result != null && orderByYear != null){
		for(int i=0;i<result.length;i++){
			if(orderByYear[i][0] == 0 ) continue;
			String rel ="";
			switch(i+1){
				case 1:
					rel = "write";
					break;
				case 2:
					rel = "edit";
					break;
				case 3:
					rel = "cite";
					break;
				case 4:
					rel = "inproceedings";
					break;
				case 5:
					rel = "publish";
					break;
				case 6:
					rel = "";
					break;
			}%>
			
			<strong id="relation_strong">		
			
<%			if(result[i][0].equals("1")){	%>
				<%=rel + "--> &nbsp;"%>
<%				}else if(result[i][0].equals("-1")){%>
				<%="<--" + rel + "&nbsp;"%>
<%				}else{%>
				<%="&nbsp;"%>
<%				}%>

		</strong>
		
<%		columns = result[i][orderByYear[i][0]].split("@@");//get the title info		
			String type = "";
			String[] titles = new String[columns.length-2];//except id && type
			for(int j=1;j<columns.length;j++){
				if(j == 1){
					type = columns[j].split(":")[1];
				}else{
					titles[j-2] = columns[j].split(":")[0];
				}
			}%>
		
			<table border="1" id="tb_out" cellspacing=0   cellpadding=0>
			<tr>
				<td>
					<table  border="1">
							<tr><strong id="type_strong">	<%=type%></strong></tr>
					</table>
				</td>
				<td>
					<table  id="tb">						

<%		//output the table ,first th
			for(int j = 0;j<titles.length;j++){%>
				<th>
					<%=titles[j]%>
				</th>
<%		}%>
			<th><%="&nbsp;"%></th>

<%		for(int j=1;j<orderByYear[i].length;j++){//output tr && td
				columns = result[i][orderByYear[i][j]].split("@@");%>
				<tr>			
<%					for(int k=0; k<titles.length;k++){%>
						<td>
<%						int h;
							for(h=2;h<columns.length;h++){
								if(columns[h].split(":")[0].equals(titles[k])){
							          rel = columns[h].split(":")[1];%>
									<%=columns[h].split(":")[1]%>
	<%								break;
								}
							}
							if(h == columns.length){%>
								<%="&nbsp;"%>
	<%					}%>
						</td>
<%					}%>
					<td>
						<%="<a href=\"/WebSearch/MoreInfo?id="+columns[0]+"\">Enter</a>"%>
					</td>
				</tr>
<%		}%>		

	</table>
				</td>
			</tr>
</table>
<br>
<%		}//end first for
	}// end if
%>
	
</DIV>
</body>
</html>